<?php

 /**
 Featured Categories
 */
 require($template->get_template_dir('tpl_modules_featured_category_row.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_featured_category_row.php');


/**
 Featured Products
 */
  $recommended_products_sql = "SELECT p.`products_id`,p.`products_quantity`,p.`product_is_wholesale`,pd.`products_name`, p.`products_image`, p.`products_price`,p.`products_price_retail`,p.`products_price_sample` FROM featured f, products p, products_to_categories pt, products_description pd
	WHERE p.products_id=f.products_id AND p.`products_status` = 1 AND pt.products_id=p.products_id AND pd.products_id=f.products_id order by p.`products_id` desc";
	
		$recommended_products = $db->ExecuteRandomMulti($recommended_products_sql, '3');
		
		if($recommended_products->RecordCount()>0){
			while (!$recommended_products->EOF){
				$recommended_products_items[] = $recommended_products->fields;
				$recommended_products_id_con[]	= $recommended_products->fields['products_id'];
				$recommended_products_images_con[]	= '"'.(zen_not_null($recommended_products->fields['products_image']) ? $recommended_products->fields['products_image'] : PRODUCTS_IMAGE_NO_IMAGE ).'"';
				$recommended_products_source_price_con[]	= '"'.$currencies->display_price($recommended_products->fields['products_price_retail'],zen_get_tax_rate($product_check->fields['products_tax_class_id'])).'"';
				$recommended_products_price_con[]	= '"'.$currencies->display_price(($recommended_products->fields['products_price'] == 0 ? $recommended_products->fields['products_price_sample']: $recommended_products->fields['products_price']),zen_get_tax_rate($product_check->fields['products_tax_class_id'])).'"';
				$recommended_products_sub_name_con[]	= '"'.zen_clipped_string(addslashes(zen_output_string($recommended_products->fields['products_name'])),' ',18).'"';
				$recommended_products_name_con[]	= '"'.zen_output_string($recommended_products->fields['products_name']).'"';
	
	      $sold_out_s = ($recommended_products->fields['products_quantity'] <= 0)? 1 : 0 ;
	      $almost_sold_out_s = ( 0 < $recommended_products->fields['products_quantity'] and $recommended_products->fields['products_quantity'] <10)? 1 : 0;
	      $product_count_s = 0;
	      $sale_item_s = $recommended_products->fields['product_is_wholesale)'];
				$recommended_products_flg_con[] = '"'.$sold_out_s.'#'.$almost_sold_out_s.'#'.$product_count_s.'#'.$sale_item_s.'"';
				$recommended_products->MoveNextRandom();
			}
			$recommended_products_id = implode(",", $recommended_products_id_con);
			$recommended_products_images = implode(",", $recommended_products_images_con);
			$recommended_products_source_price = implode(",", $recommended_products_source_price_con);
			$recommended_products_price = implode(",", $recommended_products_price_con);
			$recommended_products_sub_name = implode(",", $recommended_products_sub_name_con);
			$recommended_products_name = implode(",", $recommended_products_name_con);
			$recommended_products_flg = implode(",",$recommended_products_flg_con);
		}
		$recommended_display_num = ( count($recommended_products_items) < 3) ? count($recommended_products_items) : 3 ;
		if($recommended_products->RecordCount()>0){
		
?>
<div class="clear"></div>
<div class="proutbar">
	<div id="featuredProducts" class="centerBoxWrapper">
	<h2 class="red in_1em line_30px">Featured Products</h2>
	<?php 
	$coloum =0;
	for($i=0; $i<$recommended_display_num ; $i++){ 
	?>
	<div class="centerBoxContentsFeatured centeredContent back"> 
	<br>
	<a href="<?php echo zen_href_link(zen_get_info_page($recommended_products_items[$i]['products_id']), 'products_id=' . $recommended_products_items[$i]['products_id']); ?>">
	<?php echo zen_image_OLD(DIR_WS_IMAGES.$recommended_products_items[$i]['products_image'],SEO_COMMON_KEYWORDS.' '.$recommended_products_name_con[$i],120,120,'id="cell_img'.$i.'"');?>
	<br />
	<?php echo zen_clipped_string($recommended_products_items[$i]['products_name'],' ',100); ?>
	</a>
	<strong class="red"><?php echo $currencies->display_price(($recommended_products_items[$i]['products_price'] == 0 ? $recommended_products_items[$i]['products_price_sample']: $recommended_products_items[$i]['products_price']),zen_get_tax_rate($recommended_products_items[$i]['products_id'])) ?></strong>

	</div>	
	<?php
	if($coloum == 2)
	{
		$coloum =0;
	?>

		<br class="clearBoth">
	<?php
	
	}else
	{
		$coloum +=1;
	}
	}
	?>
	</div>
</div>


<?php
}
?>